//
//  ViewController.m
//  PPostAudioFunction
//
//  Created by carlos on 14-5-2.
//  Copyright (c) 2014年 carlosk. All rights reserved.
//

#import "ViewController.h"
#import "PPostVideoHandler.h"

@interface ViewController ()
@property(nonatomic,strong)PPostVideoHandler  * handler;
@property(nonatomic,weak)IBOutlet UIButton *btnRecord;
@property(nonatomic,strong)NSString  * pathFile;//缓存的路径

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.handler = [[PPostVideoHandler alloc] init];
    self.handler.doEndRecord = ^(NSString *filePath,NSString *fileName){
        NSLog(@"filePath = %@,fileName = %@",filePath,fileName);
        self.pathFile = filePath;
    };
    //添加长按手势
    UILongPressGestureRecognizer *longPrees = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(recordBtnLongPressed:)];
    [self.btnRecord addGestureRecognizer:longPrees];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)onClickBtn:(UIView *)sender{
    if (sender.tag == 0) {
        //录音

    }else{
        //播放
        [PPostVideoHandler play:self.pathFile];
    }
}
#pragma mark - 长按录音
- (void)recordBtnLongPressed:(UILongPressGestureRecognizer*) longPressedRecognizer{
    //长按开始
    if(longPressedRecognizer.state == UIGestureRecognizerStateBegan) {
        [self.handler startRecord:self.view];
        NSLog(@"开始");
    }//长按结束
    else if(longPressedRecognizer.state == UIGestureRecognizerStateEnded || longPressedRecognizer.state == UIGestureRecognizerStateCancelled){
        NSLog(@"结束");
        [self.handler endRecord];
    }
}

@end
